package com.tianjipms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tianjipms.dao.VehicleAccessMapper;
import com.tianjipms.entity.VehicleAccess;
import com.tianjipms.service.VehicleAccessService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

@Service
@Transactional
public class VehicleAccessServiceImpl extends ServiceImpl<VehicleAccessMapper, VehicleAccess> implements VehicleAccessService {
    @Resource
    private VehicleAccessMapper vehicleAccessMapper;
    @Override
    public IPage<VehicleAccess> findVehiclAccessListByLicenseNumberPage(IPage<VehicleAccess> page, String licenseNumber) {
        QueryWrapper<VehicleAccess> queryWrapper = new QueryWrapper<VehicleAccess>();
        queryWrapper.like(!ObjectUtils.isEmpty(licenseNumber),"license_number", licenseNumber);
        return vehicleAccessMapper.selectPage(page, queryWrapper);
    }

    @Override
    public IPage<VehicleAccess> findVehiclAccessListByTimePage(IPage<VehicleAccess> page, Date startTime, Date endTime) {
        QueryWrapper<VehicleAccess> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("enter_time", startTime, endTime)
                    .or()
                    .between("leave_time", startTime, endTime);
        return vehicleAccessMapper.selectPage(page,queryWrapper);
    }
}
